package com.macro.mall.controller;

import com.macro.mall.common.api.CommonResult;
import com.macro.mall.dto.DashboardStatsDTO;
import com.macro.mall.dto.DashboardTrendDTO;
import com.macro.mall.service.DashboardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDate;

@RestController
@Api(tags = "DashboardController")
@Tag(name = "DashboardController", description = "数据看板管理")
@RequestMapping("/dashboard")
public class DashboardController {

    @Resource
    private DashboardService dashboardService;

    /**
     * 获取核心业务指标
     */
    @ApiOperation("获取核心业务指标")
    @RequestMapping(value = "/stats", method = RequestMethod.GET)
    public CommonResult<DashboardStatsDTO> getStats(
            @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate,
            @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate) {
        
        DashboardStatsDTO stats = dashboardService.getStats(startDate, endDate);
        return CommonResult.success(stats);
    }

    /**
     * 获取趋势图数据
     */
    @ApiOperation("获取趋势图数据")
    @RequestMapping(value = "/trend", method = RequestMethod.GET)
    public CommonResult<DashboardTrendDTO> getTrend(
            @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate,
            @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate) {
        
        DashboardTrendDTO trend = dashboardService.getTrend(startDate, endDate);
        return CommonResult.success(trend);
    }
}
